<?php
namespace app\admin\controller;
use think\Db;
use lib\Curl;
class Server extends Base{
    //广告图
    public function server_banner(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_banner')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['banner']=$param['banner'];
            $data['title_en']=$param['title_en'];
            $res= Db::name('server_banner')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function server_express(){
        $list=Db::name('server_express')->order('id desc')->paginate(10);
        $counts=Db::name('server_express')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function server_express_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['detail']=html_entity_decode($param['detail']);
            $res= Db::name('server_express')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_express_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_express')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['detail']=html_entity_decode($param['detail']);
            $res=Db::name('server_express')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_express_del(){
        $param = input('post.');
        $res= Db::name('server_express')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function server_express_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_ex_l')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['title_en']=$param['title_en'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('server_ex_l')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_process(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_process')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $data['img_o']=$param['img_o'];
            $data['img_t']=$param['img_t'];
            $data['img_th']=$param['img_th'];
            $data['img_o_title']=$param['img_o_title'];
            $data['img_t_title']=$param['img_t_title'];
            $data['img_th_title']=$param['img_th_title'];
            $data['img_process']=$param['img_process'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res= Db::name('server_process')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }

    public function server_superiority(){
        $list=Db::name('server_superiority')->order('id desc')->paginate(10);
        $counts=Db::name('server_superiority')->count();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('counts',$counts);
        return $this->fetch();
    }
    public function server_superiority_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['detail']=html_entity_decode($param['detail']);
            $res= Db::name('server_superiority')->insertGetId($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_superiority_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_superiority')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['detail']=html_entity_decode($param['detail']);
            $res=Db::name('server_superiority')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_superiority_del(){
        $param = input('post.');
        $res= Db::name('server_superiority')->where(array('id'=>$param['id']))->delete();
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function server_superiority_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_sup_l')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['title_en']=$param['title_en'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('server_sup_l')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
    public function server_ensure(){
        $list=Db::name('server_ensure')->where('state',1)->order('id desc')->paginate(10);
        $lists=Db::name('server_ensure')->where('state',1)->select();
        $data=$list->all();
        $this->assign('data',$data);
        $this->assign('list',$list);
        $this->assign('lists',$lists);
        return $this->fetch();
    }
    public function server_ensure_add(){
        if(request()->isGet()){
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $data['time']=time();
            $data['uptime']=time();
            $res=Db::name('server_ensure')->insert($data);
            if($res){
                return json(['code' => 200,'msg' => '成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function server_ensure_edit(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_ensure')->where('id',$param['id'])->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['img']=$param['img'];
            $data['title']=$param['title'];
            $data['description']=$param['description'];
            $data['sort']=$param['sort'];
            $data['uptime']=time();
            $res= Db::name('server_ensure')->where(array('id'=>$param['id']))->update($data);
            if($res){
                return json(['code' => 200,'msg' => '更新成功']);
            }else{
                return json(['code' => 500,'msg' => '失败']);
            }
        }
    }
    public function server_ensure_del(){
        $param = input('post.');
        $res= Db::name('server_ensure')->where(array('id'=>$param['id']))->update(['state'=>3]);
        return json(['code' => 200,'msg' => '删除成功']);

    }
    public function server_ensure_set(){
        if(request()->isGet()){
            $param = input('get.');
            $data=Db::name('server_ensure_title')->where('id',1)->find();
            $this->assign('data',$data);
            return $this->fetch();
        }elseif(request()->isPost()){
            $param = input('post.');
            $data['title']=$param['title'];
            $data['subtitle']=$param['subtitle'];
            $data['seo_keywords']=$param['seo_keywords'];
            $data['seo_description']=$param['seo_description'];
            $res=Db::name('server_ensure_title')->where(array('id'=>1))->update($data);
            if($res){
                return json(['code' => 200, 'msg' => '成功！']);
            }else{
                return json(['code' => 500, 'msg' => '失败！']);
            }
        }
    }
}